#!bin/sh
CRTDIR=$(cd `dirname $0`; pwd)

count=`ps -ef | grep imapi-socket-2.0.war | grep -v "grep" | wc -l`
if [ $count -gt 0 ]; then
 echo "api is running!!  please stop it first!!!"
 exit 0
else
 echo "now start api..."
fi

# 判断是否有tmp文件夹，没有则创建，用于存储jsp编译后的文件
if [ -d "${CRTDIR}/tmp" ]; then
  rm -rf ${CRTDIR}/tmp
fi

configFile=${CRTDIR}/application-local.properties,${CRTDIR}/application.properties
nohup java -XX:+UseG1GC -Xms#Api_ServerMem# -Xmx#Api_ServerMem# -jar ${CRTDIR}/im-api-3.0.war --spring.config.location=${configFile} --logging.config=${CRTDIR}/logback-spring.xml > /dev/null 2>&1 &

echo "api服务器正在启动中,请稍后......"
sleep 3

while( [ ! -e ${CRTDIR}/logs/api.log ]  )
do
  echo 'Wait for the api.log file to be generated...'
  /usr/bin/sleep 2
done

if [ -z $1 ];then
	tail -f ${CRTDIR}/logs/api.log
fi
